<script setup>
import axios from "axios";
import {reactive, onMounted} from "vue";

let jsonData = reactive({
      "code": 1, "content": "我努力不是为了你而是因为你。"
    }
);
let getLoveMessage = async () => {
  let {data} = await axios.post(
      "api/rand.qinghua?format=json" , // 请求地址
      {
        username:'zhangsan',
        password:'123456'
      },//请求体中的JSON数据
      {
        params:{
          format:'json',
        }
      }// 其他键值对参数
  )
  console.log(data);
  ////对象合并 先写对象在写来源对象
  Object.assign(jsonData, data);
  console.log(123);
};
// 刷新页面获取一次
onMounted(() => {
  getLoveMessage();
})
</script>

<template>
  <div>
    <h1>AxiosTest</h1>
    <input type="text"><br/>
    <h2>今日情话：{{ jsonData.content }}</h2>
    <button @click="getLoveMessage">获取今日土味情话</button>
  </div>
</template>

<style scoped>

</style>